package com.gxa.zhonglong.service.impl;

import com.gxa.zhonglong.common.ExceptionCode;
import com.gxa.zhonglong.exception.BusinessException;
import com.gxa.zhonglong.mapper.HeadquartersMapper;
import com.gxa.zhonglong.pojo.Headquarters;
import com.gxa.zhonglong.service.HeadquartersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/10/26 14:51
 * Description:
 * Version: V1.0
 */
@Service
public class HeadquartersServiceImpl implements HeadquartersService {

    @Autowired
    private HeadquartersMapper headquartersMapper;

    @Override
    public List<Map<String, Object>> selectAll() {
        return headquartersMapper.selectAll();
    }

    @Override
    public List<Map<String, Object>> selectIdAndName() {
        return headquartersMapper.selectIdAndName();
    }

    @Override
    public Map<String, Object> selectById(Long id) throws BusinessException {
        final Map<String, Object> stringObjectMap = headquartersMapper.selectById(id);
        if (stringObjectMap==null){
            throw new BusinessException(ExceptionCode.NODATA);
        }
        return stringObjectMap;
    }

    @Override
    public void add(Headquarters headquarters) throws BusinessException {
        if (!headquartersMapper.add(headquarters)) {
            throw new BusinessException(ExceptionCode.ADD_DEFEATED);
        }
    }

    @Override
    public void update(Headquarters headquarters) throws BusinessException {
        if (!headquartersMapper.update(headquarters)) {
            throw new BusinessException(ExceptionCode.UPDATE_FALSE);
        }
    }

    @Override
    public void del(Long id) throws BusinessException {
        if (!headquartersMapper.del(id)) {
            throw new BusinessException(ExceptionCode.DELETE_FALSE);
        }
    }
}
